﻿@model IEnumerable<Classified.Domain.Entities.AttributeValue>
@{
    ViewBag.Title = "List of Classified Ads";
    Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
}
<h1>
    List <small>of @ViewBag.CategoryName 's @ViewBag.AttributesName</small></h1>
<p align="right" style="float: left" class="noprint">
    <a href="javascript:void(0)" idAttr="@ViewBag.AttributesID" class="btn btn-info newDetailLocation">
        <i class="icon-plus icon-white"></i>Create new</a> <a href="@Url.Action("Attributes", "Classified")" class="btn">
            Back to List</a>
    </p>
    <table class="table table-bordered table-striped">
        <thead>
            <th>
                Name
            </th>
            <th>
                Attibute Name
            </th>
            <th class="noprint" width="30%">
            </th>
        </thead>
        @foreach (var item in Model)
        {
            <tr>
                <td>
                    @Html.DisplayFor(modelItem => item.Value)
                </td>
                <td>
                    @Html.DisplayFor(modelItem => item.ClassifiedCategoryAttributes.Attr_Name)
                </td>
                <td>
                    <a href="@Url.Action("EditAttributesVaulues", "Classified", new { id = item.Id })" idLocationDetails ="@item.Id"  class="btn btn-primary editLocationDetails" idLocationDetails="@item.Id">
                        <i class=" icon-edit icon-white"></i>Edit</a> <a href="@Url.Action("DeleteAttributesVaulues", "Classified", new { id = item.Id })" class="btn btn-danger" onclick="return confirm('Are you sure you wish to delete this Attributes Vlaues?');">
                            <i class="icon-trash icon-white"></i>Delete</a>
                </td>
            </tr>
        }
    </table>
    <script language="javascript" type="text/javascript">
        function clearErrors() {
            $('#msgErrorNewLocationDetails').html('');
            $('#msgError').html('');
        }

        function writeError(control, msg) {
            var err_msg = '<div class="alert-message error"><a class="close" href="#">×</a><p>' + msg + '</p></div>';
            $('#' + control).html(err_msg);
        }

        $(document).ready(function () {

            $('.closeModal').live('click', function () {
                $('#my-modal').modal('hide');
            });
            $('.close').live('click', function () {
                $('#my-modal').modal('hide');
            });

            $('#my-modal form').live('submit', function () {
                clearErrors();

                $.post($(this).attr('action'), $(this).serialize(), function (data, status) {
                    $('#my-modal').modal('hide');
                    window.location.reload(true);

                }).error(function (error, status, a, b) {
                    writeError('msgError', 'Error processing request. Please check errors and try again!');
                    $('.modal-body p.body').html(error.responseText);

                });
                return false;
            });

            function getRequest(url) {
                $.ajax({
                    url: url,
                    context: document.body,
                    success: function (data) {
                        $('.modal-body p.body').html(data);
                        $(this).addClass("done");
                        $('#my-modal').modal('show');
                        $('#Article').focus();
                    },
                    error: function (err) {
                        writeError('msgErrorNewLocationDetails', err);
                    }
                });
            }

            $('a.newDetailLocation').live('click', function () {
                clearErrors();

                var id = $(this).attr("idAttr");

                var url = '@Url.Content("~/Admin/Classified/CreateAttributesVaulues")/' + id;
                getRequest(url);

                return false;
            });


            $('.editLocationDetails').live('click', function () {
                clearErrors();

                var id = $(this).attr("idLocationDetails");
                var url = '@Url.Content("~/Admin/Classified/EditAttributesVaulues")/' + id;

                getRequest(url);

                return false;
            });




        }); 
    </script>
    <div id="locationDetailsList">
    </div>
    <div id="my-modal" class="modal hide fade">
        <div class="modal-header">
            <a href="#" class="close">&times;</a>
            <h3>
                Attributes details</h3>
        </div>
        <div class="modal-body">
            <div id="msgError">
            </div>
            <p class="body">
            </p>
        </div>
        <div class="modal-footer">
        </div>
    </div>
